import * as vscode from 'vscode';
export async function algGPTSidebar(context: vscode.ExtensionContext) {
    console.log('恭喜你，你的扩展“algGPT”现在是活跃的!');

    const provider = new AlgGPTViewProvider(context);
    context.subscriptions.push(vscode.window.registerWebviewViewProvider(AlgGPTViewProvider.viewType, provider));

}


class AlgGPTViewProvider implements vscode.WebviewViewProvider {
    public static readonly viewType = 'algGPTSidebar';
    private webview: vscode.Webview | undefined;

    constructor(private readonly vscodeContext: vscode.ExtensionContext) {
    }

    public resolveWebviewView(
        webviewView: vscode.WebviewView,
        context: vscode.WebviewViewResolveContext,
        _token: vscode.CancellationToken
    ): void {
        this.webview = webviewView.webview;
        webviewView.webview.options = {
            enableScripts: true,
            localResourceRoots: [this.vscodeContext.extensionUri]
        };
        webviewView.webview.html = this.getHtmlForWebview(webviewView.webview);

    }

    private getHtmlForWebview(webview: vscode.Webview): string {

        return `
        <!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Webview</title>
        </head>
        <body>
            <iframe src="http://googlevip8.com/chat/share?shareId=mkq8toty78bh8ff1ulq12tcj" style="width:100%; height:calc(100vh - 10px); border:none;"></iframe>
        </body>
        </html>`;
    }
}
